var index = parent.layer.getFrameIndex(window.name);
$(function () {
    $('.skin-minimal input').iCheck({
        checkboxClass: 'icheckbox-blue',
        radioClass: 'iradio-blue',
        increaseArea: '20%'
    });
    init();
    //表单验证
    $("#form-article-add").validate({
        rules: {
            articleTitle: {
                required: true
            },
            prefTitle: {
                required: true,
            },
            commentBeginTime: {
                required: true
            },
            commentEndTime: {
                required: true
            }
        },
        onkeyup: false,
        focusCleanup: true,
        success: "valid",
        submitHandler: function (form) {
            $(form).append("allowComments", $('#allowComments').attr('checked'));
            $(form).ajaxSubmit();
            //parent.$('.btn-refresh').click();
            localStorage.removeItem("article_update_frame_articleId");
            parent.layer.close(index);
        }
    });


});

function init() {

    var articleId = localStorage.getItem("article_update_frame_articleId");
    $.ajax({
        url: "/Olala/article/getArticleById",
        data: {
            articleId: articleId
        },
        dataType: "json",
        type: "post",
        async: false,
        success: function (result) {
            initForm(result.data);
        }
    });
}

function initForm(article) {
    $("#articleId").val(article.articleId);
    $("#articleTitle").val(article.articleTitle);
    $("#prefTitle").val(article.prefTitle);
    $("#articleType").val(article.articleType);
    $("#keywords").val(article.keywords);
    $("#abstracts").text(article.abstracts);
    $("#content").text(article.content);
    $("#author").val(article.author);
    $("#source").val(article.source);
    $("#commentBeginTime").val(article.commentBeginTime);
    $("#commentEndTime").val(article.commentEndTime);
    $("#allowComments").prop("checked", article.commentEndTime);
}